package com.sram.action;

import java.io.File;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;

import org.apache.commons.io.FileUtils;
import org.apache.struts2.ServletActionContext;



public class UpdownAction{
	private File uploadImage;//得到上传的文件
	 private String uploadImageContentType;//得到文件的类型
	 private String uploadImageFileName;//得到文件的名称
	  
	 public File getUploadImage() {
		return uploadImage;
	}

	public void setUploadImage(File uploadImage) {
		this.uploadImage = uploadImage;
	}

	public String getUploadImageContentType() {
		return uploadImageContentType;
	}

	public void setUploadImageContentType(String uploadImageContentType) {
		this.uploadImageContentType = uploadImageContentType;
	}

	public String getUploadImageFileName() {
		return uploadImageFileName;
	}

	public void setUploadImageFileName(String uploadImageFileName) {
		this.uploadImageFileName = uploadImageFileName;
	}

	public String upload() throws Exception{
		@SuppressWarnings("unused")
		String name1 = (String) ServletActionContext.getRequest().getSession().getAttribute("username");

		 String realpath = ServletActionContext.getServletContext().getRealPath("")+"\\WEB-INF\\images";
		 System.out.println("wwwwwwwwwwwwwwww");
		 String rootPath1=getClass().getResource("/").getFile().toString();
		 System.out.println(rootPath1);

		 System.out.println(realpath);
		 System.out.println(uploadImage);
		 System.out.println(uploadImageFileName);

		 File file = new File(realpath);
		  FileUtils.copyFile(uploadImage, new File(file, uploadImageFileName));
		return "success";
	 }
	
}
